package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.common.MessageConst;
import com.itheima.common.RedisMessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.ValidateCodeService;
import com.itheima.utils.ValidateCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/validateCode")
public class ValidateCodeController {

    @Reference
    ValidateCodeService validateCodeService;

    @RequestMapping("/send4Order")
    public Result send4Order(String telephone){
        log.debug("付1--获得前端传来的手机号:"+telephone);
        String validatecode = String.valueOf(ValidateCodeUtils.generateValidateCode(4));
        log.debug("付2--验证码是--"+validatecode);
        validateCodeService.sendValidateCodeShortMessage(telephone,RedisMessageConstant.SENDTYPE_ORDER,validatecode);
        return new Result(true, MessageConst.SEND_VALIDATECODE_SUCCESS);
    }


    @RequestMapping("/send4Login")
    public Result send4Login(String telephone){
        log.debug("付1--获得前端传来的手机号:"+telephone);
        String validatecode = String.valueOf(ValidateCodeUtils.generateValidateCode(4));
        log.debug("付2--验证码是--"+validatecode);
        validateCodeService.sendValidateCodeShortMessage(telephone,RedisMessageConstant.SENDTYPE_LOGIN,validatecode);
        return new Result(true, MessageConst.SEND_VALIDATECODE_SUCCESS);
    }


}
